import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class LoadingUtil {
  // 初始化 EasyLoading 配置
  static void init() {
    EasyLoading.instance
      ..loadingStyle = EasyLoadingStyle.light
      ..indicatorType = EasyLoadingIndicatorType.ring
      ..maskType = EasyLoadingMaskType.black
      ..userInteractions = false
      ..dismissOnTap = false;
  }

  // 显示加载
  static void showLoading({
    String? text,
    Widget? indicator,
    EasyLoadingMaskType? maskType,
    bool? dismissOnTap,
  }) {
    EasyLoading.show(
      status: text,
      indicator: indicator,
      maskType: maskType,
      dismissOnTap: dismissOnTap,
    );
  }

  // 显示成功信息
  static void showSuccess(
    String text, {
    Duration? duration,
    EasyLoadingMaskType? maskType,
    bool? dismissOnTap,
  }) {
    EasyLoading.showSuccess(
      text,
      duration: duration ?? const Duration(milliseconds: 1000),
      maskType: maskType,
      dismissOnTap: dismissOnTap,
    );
  }

  // 显示错误信息
  static void showError(
    String text, {
    Duration? duration,
    EasyLoadingMaskType? maskType,
    bool? dismissOnTap,
  }) {
    EasyLoading.showError(
      text,
      duration: duration,
      maskType: maskType,
      dismissOnTap: dismissOnTap,
    );
  }

  // 显示信息
  static void showInfo(
    String text, {
    Duration? duration,
    EasyLoadingMaskType? maskType,
    bool? dismissOnTap,
  }) {
    EasyLoading.showInfo(
      text,
      duration: duration,
      maskType: maskType,
      dismissOnTap: dismissOnTap,
    );
  }

  // 显示提示
  static void showToast(
    String text, {
    Duration? duration,
    EasyLoadingToastPosition? toastPosition,
    EasyLoadingMaskType? maskType,
    bool? dismissOnTap,
  }) {
    EasyLoading.showToast(
      text,
      duration: duration,
      toastPosition: toastPosition,
      maskType: maskType,
      dismissOnTap: dismissOnTap,
    );
  }

  // 显示进度
  static void showProgress(
    double progress, {
    String? text,
    EasyLoadingMaskType? maskType,
  }) {
    EasyLoading.showProgress(
      progress,
      status: text,
      maskType: maskType,
    );
  }

  // 隐藏加载
  static void dismiss() {
    EasyLoading.dismiss();
  }
}
